<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => 'admin'], function () {
    // 授权
    Route::post('login', 'AuthenticateController@login');
    // 回收授权
    Route::post('logout', 'AuthenticateController@logout');

    Route::group(['middleware' => 'authenticate', 'scopes' => 'admin'], function(){
        // 登录后获取用户信息
        Route::get('profile', 'AuthenticateController@profile');

        /**
         * 用户管理
         */
        Route::get('users', 'UserController@index');
        Route::get('users/userslist', 'UserController@userslist');
        Route::get('users/{id}', 'UserController@show');
        Route::post('users/{id}/check', 'UserController@check');

        /**
         * 店铺管理
         */
        Route::get('shops', 'ShopController@index');
        Route::post('shops', 'ShopController@store'); // 创建自营店
        Route::post('shops/toggle-status', 'ShopController@toggleStatus');
        Route::get('shops/login-to-manager/{id}', 'ShopController@loginToManager');
        Route::get('stores/checklist', 'StoreController@checklist');
        Route::get('stores/{id}', 'StoreController@show');
        Route::post('stores/check', 'StoreController@storecheck');
        

        /**
         * 订单管理
         */
        Route::get('orders', 'OrderController@index');
        Route::get('orders/count', 'OrderController@count');
        Route::get('orders/{id}', 'OrderController@show');

        /**
         * 提现
         */
        Route::get('withdraw', 'WithdrawController@index');

        //商品管理
        Route::post('products/recommend', 'ProductController@recommend'); //商品推荐首页
        Route::post('products/uploadpic', 'ProductController@uploadpic'); //商品图片上传
        Route::get('products', 'ProductController@index');
        Route::get('products/{id}', 'ProductController@show');
        Route::post('products/store', 'ProductController@store');
        Route::put('products/{id}', 'ProductController@update'); //更新商品
        
        //商品分类管理
        Route::get('category', 'CategoryController@index');
        Route::get('category/{id}', 'CategoryController@show');
        Route::post('category/store', 'CategoryController@store');
        Route::put('category/{id}', 'CategoryController@update');

        // 幻灯片管理
        Route::post('banner/imageUpload', 'BannerController@imageUpload');
        Route::apiResource('banner', 'BannerController');

        /**
         * 财务明细
         */
        Route::get('balance-list', 'ShopBalanceLogController@index');

        /**
         * 文章管理
         */
        Route::post('articles/image-upload', 'ArticleController@imageUpload');
        Route::apiResource('articles', 'ArticleController');
    });
});


/**
 * 店铺 API
 */
Route::group(['namespace' => 'Shop', 'prefix' => 'shop', 'middleware' => 'shop'], function() {
    // 授权
    Route::post('login', 'AuthenticateController@login');
    // 回收授权
    Route::post('logout', 'AuthenticateController@logout');

    Route::group(['middleware' => 'authenticate:shop', 'scopes' => 'shop'], function() {
        // 店铺信息
        Route::get('profile', 'AuthenticateController@profile');

        /**
         * 商品
         */
        Route::post('products/{id}/toggle-status', 'ProductController@toggleStatus'); // 商品上下架
        Route::post('products/destroy-batch', 'ProductController@destroyBatch'); // 批量删除
        Route::post('products/uploadpic', 'ProductController@imageUpload'); // 商品图片上传
        Route::apiResource('products', 'ProductController');

        /**
         * 商品分类
         */
        Route::get('categories', 'CategoryController@index');

        /**confirm
         * 订单
         */
        Route::post('orders/{id}/confirm', 'OrderController@confirm'); // 确认
        Route::post('orders/{id}/cancel', 'OrderController@cancel'); // 取消
        Route::post('orders/{id}/deliver', 'OrderController@deliver'); // 发货
        Route::apiResource('orders', 'OrderController');

        /**
         * 财务明细
         */
        Route::get('balance-list', 'ShopBalanceLogController@index');

        /**
         * 提现
         */
        Route::get('withdraw', 'WithdrawController@index');
        Route::post('withdraw/cash', 'WithdrawController@cash');

        /**
         * 店铺
         */
        Route::get('details', 'ShopController@details'); // 店铺详情
        Route::put('info-update/{id}', 'ShopController@update'); // 店铺详情
        Route::get('real-name-info', 'ShopController@realNameInfo'); // 实名认证信息
        Route::post('real-name-verification', 'ShopController@realNameVerification'); // 实名认证信息
    });
});